package com.zhongxi.guoyuan.adapter.rewardCoin;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.seller.BillData;
import com.zhongxi.guoyuan.entity.seller.BillOrderInfo;

import java.util.List;

/**
 * Created by Administrator on 2017/8/30.
 */

public class RewardBillAdapter extends BaseAdapter {
    private Context context;
    private List<BillOrderInfo> list;

    public RewardBillAdapter(Context context, List<BillOrderInfo> data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_order_info, parent, false);
            holder.tvDate = (TextView) convertView.findViewById(R.id.tvTime);
            holder.tvOrderId = (TextView) convertView.findViewById(R.id.tvOrderId);
            holder.tvCash = (TextView) convertView.findViewById(R.id.tvCash);
            holder.tvReward = (TextView) convertView.findViewById(R.id.tvCoin);
            holder.linearBackground = (LinearLayout) convertView.findViewById(R.id.linearBackground);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvReward.setVisibility(View.GONE);

        if (position % 2 == 0) {
            holder.linearBackground.setBackgroundColor(context.getResources().getColor(R.color.bg_box_one));
        } else {
            holder.linearBackground.setBackgroundColor(context.getResources().getColor(R.color.bg_box_two));
        }
        if (null != list.get(position) && !"".equals(list.get(position))) {
            BillOrderInfo data = list.get(position);
            if (null != data.getPaytime() && !"".equals(data.getPaytime())) {
                holder.tvDate.setText(data.getPaytime());
            } else {
                holder.tvDate.setText("");
            }
            if (null != data.getId() && !"".equals(data.getId())) {
                holder.tvOrderId.setText(data.getId());
            } else {
                holder.tvOrderId.setText("");
            }
            if (null != data.getPrice() && !"".equals(data.getPrice())) {
                holder.tvCash.setText(data.getPrice() + " 元");
            } else {
                holder.tvCash.setText("0 元");
            }
        }

        return convertView;
    }

    class ViewHolder {
        private TextView tvDate;
        private TextView tvOrderId;
        private TextView tvCash;
        private TextView tvReward;
        private LinearLayout linearBackground;
    }
}
